package com.example.udpDemo.common.utils;

import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author wangdachuan
 * @version 1.0
 * @date 2023/5/5 22:30
 **/
@Component
public class EnvironmentUtil {

    public static String name;

    public static String url;

    public static String appKey;

    @Value("${name}")
    private String tmpName;

    @Value("${url}")
    private String tmpUrl;

    @Value("${app.key}")
    private String tmpAppKey;

    /**
     * 初始化方法，使用@PostConstruct注解能够在对象通过@Component初始化后调用该方法
     * ，将通过@Value加载的值赋值给静态变量
     */
    @PostConstruct
    private void init(){name = tmpName;
        url = tmpUrl;
        appKey = tmpAppKey;
    }

}
